import RequestBean from './request_bean.ts';
import ResponseBean from './response_bean.ts';

class HttpLogBean {
  id: string;
  request: RequestBean;
  response: ResponseBean;
  createTime: Date;
  responseTime: number;

  constructor(id: string, request: RequestBean, response: ResponseBean, createTime: Date, responseTime: number) {
    this.id = id;
    this.request = request;
    this.response = response;
    this.createTime = createTime;
    this.responseTime = responseTime;
  }

  static fromJson(json: Record<string, any>): HttpLogBean {
    return new HttpLogBean(
      json['id'],
      RequestBean.fromJson(json['request']),
      ResponseBean.fromJson(json['response']),
      new Date(json['createTime']),
      json['responseTime']
    );
  }

  toJson(): Record<string, any> {
    return {
      id: this.id,
      request: this.request.toJson(),
      response: this.response.toJson(),
      createTime: this.createTime.toISOString(),
      responseTime: this.responseTime,
    };
  }
}

export { HttpLogBean, RequestBean, ResponseBean };
